package com.ncst.backend.controller;

import com.ncst.backend.common.Result;
import com.ncst.backend.domain.FeeItem;
import com.ncst.backend.domain.PharmacyRecord;
import com.ncst.backend.mapper.PharmacyRecordMapper;
import com.ncst.backend.service.PharmacyRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/pharmacyRecord")
@RequiredArgsConstructor
public class PharmacyRecordController {

    private final PharmacyRecordService service;

    /** 列表 + 搜索 */
    @GetMapping("/list")
    public Result<List<PharmacyRecord>> list(
            @RequestParam(required = false) String key,
            @RequestParam(required = false)
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)   // ← 支持 2025-09-07T12:28:35.928Z
            LocalDateTime start,
            @RequestParam(required = false)
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
            LocalDateTime end,
            @RequestParam(required = false) String state) {
        return Result.success(service.search(key, start, end, state));
    }
    /** 费用详情 */
    @GetMapping("/fee/{registerId}")
    public Result<List<FeeItem>> fee(@PathVariable Integer registerId) {
        return Result.success(service.getFeeDetail(registerId));
    }
}